package javabase.xml.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * 选择器查询（类似CSS里面的选择器语法）
 */
public class JsoupDemo5 {
    public static void main(String[] args) throws IOException {
        String path = JsoupDemo5.class.getClassLoader().getResource("student.xml").getPath();
        Document document = Jsoup.parse(new File(path), "utf-8");
        //1.查询name标签
        Elements name = document.select("name");
        System.out.println(name);
        System.out.println("******************************");
        //2.查询id值为“111”的元素
        Elements id = document.select("#111");
        System.out.println(id);
        System.out.println("***********************************");
        //3.查询number属性值为“s1001“的student标签的所有age子标签
        //3.1获取number属性值为“s1001“的student标签
        Elements select = document.select("student[number=s1001]");
        System.out.println(select);
        System.out.println("*********************************");
        //3.2查询number属性值为“s1001“的student标签的所有age子标签
        Elements age = document.select("student[number=s1001]>age");
        System.out.println(age);
    }

}
